<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class PositionExport implements FromCollection , WithHeadings, WithMapping, ShouldAutoSize
{
    private $data;
    public function __construct($data)
    {
        $this->data = $data;
    }

    public function headings() : array
    {
        return [
            '公司',
            '职位名称',
            '城市 ',
            '职位类型',
            '工作年限',
            '学历 ',
            '薪资范围',
            '职位亮点',
            '职位描述',
            '排序编号',
            '提交时间',
            '更新时间'
        ];
    }

    public function map($invoice): array
    {
        $aa =  [
            $invoice['title'],
            $invoice['position_title'],
            $invoice['city'],
            $invoice['type'],
            $invoice['age'],
            $invoice['education_background'],
            $invoice['salary'],
            $invoice['bright'],
            $invoice['desc'],
            $invoice['sort'] ?: '0',
            $invoice['created_at'],
            $invoice['updated_at'],
        ];
        return $aa;
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return new Collection($this->data);
    }
}
